package com.hornsun.account.API;

import com.hornsun.domain.dbo.User;
import com.hornsun.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * Created by 编译中... on 2018/1/27.
 */
@RestController
@RequestMapping("api/account")
public class AccountAPI {
    @Autowired
    private UserRepository userRepository;
    /**
     * 用户注册
     * @param user
     */
    @PostMapping("/addAccount")
    public void addAccount(@RequestParam User user){
        user.setUserGuid(UUID.randomUUID().toString());
        userRepository.insertUser(user);
    }

    /**
     * 修改用户信息
     * @param user
     */
    @PostMapping("/updateAccount")
    public void updateAccount(@RequestParam User user){
        userRepository.updateUser(user);
    }

    /**
     * 删除用户
     * @param userName
     */
    @PostMapping("/deleteAccount")
    public void deleteAccount(@RequestParam("userName") String userName){
        userRepository.deleteUser(userName);
    }
    /**
     * 用户登陆
     * @param username
     * @param password
     * @return
     */
    @PostMapping(value = "/login")
    public ResponseEntity<?> longin(@RequestParam("username")String username, @RequestParam("password")String password){
        long count = userRepository.getCountByUsernameAndPassword(username,password);
        if(count==1){

        }
        return null;
    }
}
